package com.uuah.server.transport.provider.mina.codecs;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * TODO comment ...
 *
 * <p>
 * update record:updator，update time，update content and version
 * </p>
 *
 * @author <a href="jonny_quan@hotmail.com">jonny</a>
 * @date 2009 2009-3-27 下午02:08:52
 * @version 1.0.0
 */
public abstract class MinaRequestResponseCodecFactory extends
		MinaProtocolCodecFactory {
	protected transient Logger logger = LoggerFactory.getLogger(getClass());
	protected boolean isServer;

	public MinaRequestResponseCodecFactory(boolean isServer) {
		this.isServer = isServer;
	}

	public ProtocolDecoder getDecoder(IoSession iosession) throws Exception {
		if (isServer) {
			return this.getServerDecoder();
		} else {
			return this.getClientDecoder();
		}
	}

	public ProtocolEncoder getEncoder(IoSession iosession) throws Exception {
		if (isServer) {
			return this.getServerEncoder();
		} else {
			return this.getClientEncoder();
		}
	}

	protected abstract ProtocolDecoder getServerDecoder() throws Exception;

	protected abstract ProtocolEncoder getServerEncoder() throws Exception;

	protected abstract ProtocolDecoder getClientDecoder() throws Exception;

	protected abstract ProtocolEncoder getClientEncoder() throws Exception;
}